<template>
  <div class="table">
    <el-table border :data="tableData" style="width: 100%">
      <template v-for="item in tableItems" :key="item.prop"
        ><el-table-column v-bind="item" align="center">
          <template #default="scope">
            <slot :name="item.slotName" :row="scope.row">
              {{ scope.row[item.prop] }}
            </slot>
          </template>
        </el-table-column>
      </template>
    </el-table>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { ITableItem } from '../types'

export default defineComponent({
  props: {
    // 接收的配置文件
    tableItems: {
      type: Array as PropType<ITableItem[]>,
      required: true,
      default: () => [],
    },
    // 接收的数据列表
    tableData: {
      type: Array,
      default: () => [],
    },
  },
  setup() {
    return {}
  },
})
</script>

<style scoped lang="less">
.table {
  padding: 20px;
  border-top: 2px solid #f5f5f5;
}
</style>
